package cn.itcast.service.cargo.impl;

import cn.itcast.dao.cargo.ShippingOrderDao;
import cn.itcast.domain.cargo.ShippingOrder;
import cn.itcast.domain.cargo.ShippingOrderExample;
import cn.itcast.service.cargo.ShippingOrderService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

@Service
public class ShippingOrderServiceImpl implements ShippingOrderService {
    @Autowired
    private ShippingOrderDao shippingOrderDao;

    @Override
    public List<ShippingOrder> findAll(ShippingOrderExample shippingOrderExample) {
        return shippingOrderDao.selectByExample(shippingOrderExample);
    }



    @Override
    public ShippingOrder findById(String id) {
        return shippingOrderDao.selectByPrimaryKey(id);
    }

    @Override
    public void save(ShippingOrder shippingOrder) {
        //补全数据
        shippingOrder.setCreateTime(new Date());

        //插入
        shippingOrderDao.insertSelective(shippingOrder);
    }

    @Override
    public void update(ShippingOrder shippingOrder) {

        shippingOrderDao.updateByPrimaryKeySelective(shippingOrder);

    }

    @Override
    public void delete(String id) {

        shippingOrderDao.deleteByPrimaryKey(id);

    }

    @Override
    public PageInfo<ShippingOrder> findByPage(ShippingOrderExample example, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);

        List<ShippingOrder> shippingOrderList = shippingOrderDao.selectByExample(example);

        PageInfo<ShippingOrder> pageInfo = new PageInfo<>(shippingOrderList);

        return pageInfo;
    }
}
